home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / C / ASCFIL.ZIP / TEST1.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-01  |  2.0 KB  |  67 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <iostream.h>
  5. #include <stdlib.h>
  6. #include <fstream.h>
  7. #include <iomanip.h>
  8. #include <conio.h>
  9. #include "table.h"
  10. #include "record.h"
  11.  
  12.  
  13. struct AFILE                // Structure to hold fields
  14. {                           // From Ascii.txt
  15.    char name[21];
  16.    char address[31];
  17.    char city[11];
  18.    char state[11];
  19.    char zip[7];
  20. };
  21.  
  22.  
  23. AFILE afile;
  24.  
  25.  
  26. main()
  27. {
  28.     int stat;
  29.     Record record("ascii.fld");           // Record Object Passing .fld file
  30.  
  31.     Table  table("ascii.txt", &record);   // Table Object passing ascii file
  32.                                           // name, and pointer to record
  33.                                           // object
  34.  
  35.     int index = record.getFieldNum("NAME");  // Init. index field
  36.     int si = table.openIndex(&index,1);      // openIndex passing pointer
  37.                                              // to field, and how many fields
  38.  
  39.  
  40.    clrscr();
  41.  
  42.    //** For Loop to read through the records...
  43.    //** Pass 'si' handle for sorted ordering, nothing for non sorted...
  44.    for (stat = table.gotoFirst(si); stat==TBL_OK; stat = table.gotoNext(si))
  45.    {
  46.        table.Get();                             // Get Record into Buffer
  47.  
  48.        record.getField("NAME", afile.name);         // Read Fields into
  49.        record.getField("ADDRESS", afile.address);   // struct... or lone
  50.        record.getField("CITY", afile.city);         // variables, doesn't
  51.        record.getField("STATE", afile.state);       // matter!
  52.        record.getField("ZIP", afile.zip);
  53.  
  54.        printf("Name    : %s\n", afile.name);        // Print Contents!
  55.        printf("Address : %s\n", afile.address);
  56.        printf("City    : %s\n", afile.city);
  57.        printf("State   : %s\n", afile.state);
  58.        printf("Zip     : %s\n", afile.zip);
  59.        printf("______________________________\n\n");
  60.    }
  61.  
  62.  table.gotoFirst(si);     // Go back to first record... for example sake...
  63.  
  64. return 0;
  65. }
  66.  
  67.